package com.jmlee.util;

/**
 * @Description 统一Redis Key管理工具类
 * @Author jmLee
 * @Date 2021/3/4 14:10
 * @Version 1.0
 */
public class RedisKeyUtil {

    private static final String SPLIT = ":";
    private static final String PREFIX_CAPTCHA = "captcha";
    private static final String PREFIX_TICKET = "ticket";

    private static final String PREFIX_ADMIN_KEY = "admin";

    private static final String PREFIX_CATEGORY = "category";

    private static final String PREFIX_SECKILL_ITEM = "seckill:item";

    private static final String PREFIX_SECKILL_STOCK = "seckill:stock";

    private static final String PREFIX_SECKILL_ORDER = "seckill:order";


    // 登录验证码
    public static String getCaptchaKey(String owner) {
        return PREFIX_CAPTCHA + SPLIT + owner;
    }

    // 登录的凭证
    public static String getTicketKey(String ticket) {
        return PREFIX_TICKET + SPLIT + ticket;
    }

    // 后台人员
    public static String getAdminKey(Long adminId) {

        return PREFIX_ADMIN_KEY + SPLIT + adminId;
    }

    // 一级根分类
    public static String getCateKey(Integer type) {

        return PREFIX_CATEGORY + SPLIT + type;
    }

    // 秒杀商品信息
    public static String getSecKillItemKey(Long itemId) {
        return PREFIX_SECKILL_ITEM + SPLIT + itemId;
    }

    // 秒杀商品库存
    public static String getSecKillStockKey(Long itemId) {

        return PREFIX_SECKILL_STOCK + SPLIT + itemId;
    }

    // 用户秒杀订单信息
    public static String getSecKillOrderKey(Long userId, Long itemId) {

        return PREFIX_SECKILL_ORDER + SPLIT + userId + "_" +itemId;
    }


}
